import java.sql.SQLOutput;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-15
 * Time: 9:42
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int count = 0;
        for (int i = a; i <= b; i++) {
            if(isMagicNum(i)) {
                count++;
            }
        }
        System.out.println(count);
    }
    private static boolean isMagicNum(int num) {
        int count = 0;
        int tmpNum = num;
        while (tmpNum != 0) {
            tmpNum /= 10;
            count++;
        }
        int[] arr = new int[count];
        tmpNum = num;
        for (int i = 0; i < count; i++) {
            arr[i] = tmpNum % 10;
            tmpNum /= 10;
        }
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < count; j++) {
                if (j != i && arr[i] != 0) {
                    int n = arr[i] * 10 + arr[j];
                    if (isPrimeNum(n)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    private static boolean isPrimeNum(int num) {
        for (int i = 2; i < num / 2; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
